<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>百度编辑器</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/layui/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
    <!-- 配置文件 -->
    <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
</head>
<body>
<div>
    <form class="layui-form layui-form-pane" action="" method="post">
        <div class="layui-form-item" >
            <label class="layui-form-label" style="height: 137px; line-height: 117px;width: 200px">运营中心头像</label>
            <input name="imgurl" id="imgurl" autocomplete="off" class="layui-input" type="hidden" value="">
            <div class=" layui-upload-drag" id="img" style="border-left: 0px;">
                <i class="layui-icon">&#xe654;</i>
                <p>Upload</p>
                <img id="demo1" style="position: absolute;height: 137px;width: 137px;margin: -106px auto auto -30px;display: none" src=""/>
            </div>
        </div>
    </form>

    <!--这里写页面的代码-->
</div>

<!-- 加载编辑器的容器 -->
<script id="container" name="content" type="text/plain">
    这里写你的初始化内容
</script>

<script type="text/javascript">
    var editor = UE.getEditor('container');
</script>

<%--layui图片上传--%>
<script>
    layui.use(['form', 'layedit', 'laydate', 'element', 'layer', 'upload','jquery'], function(){
        var form = layui.form,
            layer = layui.layer,
            element = layui.element,
            upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#img'
            , url: '/apiCommon/setImage'
            , field: 'layuiFile'

            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result, data) {
                    $('#demo1').css('display','block').attr('src', "http://localhost:8080/"+result); //链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('Upload failed');
                }
                //上传成功
                if(res.code == 0){
                    $('#imgurl').val("http://localhost:8080/"+res.data.src);
                }
            }
            , error: function (data) {

                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">Upload failed</span> <a class="layui-btn layui-btn-mini demo-reload">Retry</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });
</script>
</body>
</html>